<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="prev" href="module--winreg.html" />
<link rel="parent" href="node922.html" />
<link rel="next" href="undoc.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>36.4 winsound -- Sound-playing interface for Windows</title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="36.3.1 registry Handle Objects"
  href="handle-object.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="36. ms Windows Specific"
  href="node922.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="A. undocumented Modules"
  href="undoc.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="handle-object.html">36.3.1 Registry Handle Objects</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="node922.html">36. MS Windows Specific</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="undoc.html">A. Undocumented Modules</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h1><a name="SECTION0038400000000000000000">
36.4 <tt class="module">winsound</tt> --
         Sound-playing interface for Windows</a>
</h1>

<p>
<a name="module-winsound"></a>  
<p class="availability">Availability: <span
 class="platform">Windows</span>.</p>

<p>

<span class="versionnote">New in version 1.5.2.</span>

<p>
The <tt class="module">winsound</tt> module provides access to the basic
sound-playing machinery provided by Windows platforms.  It includes
functions and several constants.

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5843' xml:id='l2h-5843' class="function">Beep</tt></b>(</nobr></td>
  <td><var>frequency, duration</var>)</td></tr></table></dt>
<dd>
  Beep the PC's speaker.
  The <var>frequency</var> parameter specifies frequency, in hertz, of the
  sound, and must be in the range 37 through 32,767.
  The <var>duration</var> parameter specifies the number of milliseconds the
  sound should last.  If the system is not
  able to beep the speaker, <tt class="exception">RuntimeError</tt> is raised.
  <span class="note"><b class="label">Note:</b>
Under Windows 95 and 98, the Windows <tt class="cfunction">Beep()</tt>
  function exists but is useless (it ignores its arguments).  In that
  case Python simulates it via direct port manipulation (added in version
  2.1).  It's unknown whether that will work on all systems.</span>
  
<span class="versionnote">New in version 1.6.</span>

</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5844' xml:id='l2h-5844' class="function">PlaySound</tt></b>(</nobr></td>
  <td><var>sound, flags</var>)</td></tr></table></dt>
<dd>
  Call the underlying <tt class="cfunction">PlaySound()</tt> function from the
  Platform API.  The <var>sound</var> parameter may be a filename, audio
  data as a string, or <code>None</code>.  Its interpretation depends on the
  value of <var>flags</var>, which can be a bit-wise ORed combination of
  the constants described below.  If the system indicates an error,
  <tt class="exception">RuntimeError</tt> is raised.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-5845' xml:id='l2h-5845' class="function">MessageBeep</tt></b>(</nobr></td>
  <td><var></var><big>[</big><var>type=<code>MB_OK</code></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Call the underlying <tt class="cfunction">MessageBeep()</tt> function from the
  Platform API.  This plays a sound as specified in the registry.  The
  <var>type</var> argument specifies which sound to play; possible values
  are <code>-1</code>, <code>MB_ICONASTERISK</code>, <code>MB_ICONEXCLAMATION</code>,
  <code>MB_ICONHAND</code>, <code>MB_ICONQUESTION</code>, and <code>MB_OK</code>, all
  described below.  The value <code>-1</code> produces a ``simple beep'';
  this is the final fallback if a sound cannot be played otherwise.
  
<span class="versionnote">New in version 2.3.</span>

</dl>

<p>
<dl><dt><b><tt id='l2h-5846' xml:id='l2h-5846'>SND_FILENAME</tt></b></dt>
<dd>
  The <var>sound</var> parameter is the name of a WAV file.
  Do not use with <tt class="constant">SND_ALIAS</tt>.
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-5847' xml:id='l2h-5847'>SND_ALIAS</tt></b></dt>
<dd>
  The <var>sound</var> parameter is a sound association name from the
  registry.  If the registry contains no such name, play the system
  default sound unless <tt class="constant">SND_NODEFAULT</tt> is also specified.
  If no default sound is registered, raise <tt class="exception">RuntimeError</tt>.
  Do not use with <tt class="constant">SND_FILENAME</tt>.

<p>
All Win32 systems support at least the following; most systems support
  many more:

<p>
<div class="center"><table class="realtable">
  <thead>
    <tr>
      <th class="left"  ><tt class="function">PlaySound()</tt> <var>name</var></th>
      <th class="left"  >Corresponding Control Panel Sound name</th>
      </tr>
    </thead>
  <tbody>
    <tr><td class="left"   valign="baseline"><code>'SystemAsterisk'</code></td>
        <td class="left"  >Asterisk</td></tr>
    <tr><td class="left"   valign="baseline"><code>'SystemExclamation'</code></td>
        <td class="left"  >Exclamation</td></tr>
    <tr><td class="left"   valign="baseline"><code>'SystemExit'</code></td>
        <td class="left"  >Exit Windows</td></tr>
    <tr><td class="left"   valign="baseline"><code>'SystemHand'</code></td>
        <td class="left"  >Critical Stop</td></tr>
    <tr><td class="left"   valign="baseline"><code>'SystemQuestion'</code></td>
        <td class="left"  >Question</td></tr></tbody>
</table></div>

<p>
For example:

<p>
<div class="verbatim"><pre>
import winsound
# Play Windows exit sound.
winsound.PlaySound("SystemExit", winsound.SND_ALIAS)

# Probably play Windows default sound, if any is registered (because
# "*" probably isn't the registered name of any sound).
winsound.PlaySound("*", winsound.SND_ALIAS)
</pre></div>
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-5848' xml:id='l2h-5848'>SND_LOOP</tt></b></dt>
<dd>
  Play the sound repeatedly.  The <tt class="constant">SND_ASYNC</tt> flag must also
  be used to avoid blocking.  Cannot be used with <tt class="constant">SND_MEMORY</tt>.
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-5849' xml:id='l2h-5849'>SND_MEMORY</tt></b></dt>
<dd>
  The <var>sound</var> parameter to <tt class="function">PlaySound()</tt> is a memory
  image of a WAV file, as a string.

<p>
<span class="note"><b class="label">Note:</b>
This module does not support playing from a memory
  image asynchronously, so a combination of this flag and
  <tt class="constant">SND_ASYNC</tt> will raise <tt class="exception">RuntimeError</tt>.</span>
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-5850' xml:id='l2h-5850'>SND_PURGE</tt></b></dt>
<dd>
  Stop playing all instances of the specified sound.
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-5851' xml:id='l2h-5851'>SND_ASYNC</tt></b></dt>
<dd>
  Return immediately, allowing sounds to play asynchronously.
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-5852' xml:id='l2h-5852'>SND_NODEFAULT</tt></b></dt>
<dd>
  If the specified sound cannot be found, do not play the system default
  sound.
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-5853' xml:id='l2h-5853'>SND_NOSTOP</tt></b></dt>
<dd>
  Do not interrupt sounds currently playing.
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-5854' xml:id='l2h-5854'>SND_NOWAIT</tt></b></dt>
<dd>
  Return immediately if the sound driver is busy.
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-5855' xml:id='l2h-5855'>MB_ICONASTERISK</tt></b></dt>
<dd>
  Play the <code>SystemDefault</code> sound.
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-5856' xml:id='l2h-5856'>MB_ICONEXCLAMATION</tt></b></dt>
<dd>
  Play the <code>SystemExclamation</code> sound.
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-5857' xml:id='l2h-5857'>MB_ICONHAND</tt></b></dt>
<dd>
  Play the <code>SystemHand</code> sound.
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-5858' xml:id='l2h-5858'>MB_ICONQUESTION</tt></b></dt>
<dd>
  Play the <code>SystemQuestion</code> sound.
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-5859' xml:id='l2h-5859'>MB_OK</tt></b></dt>
<dd>
  Play the <code>SystemDefault</code> sound.
</dd></dl>

<p>


<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="36.3.1 registry Handle Objects"
  href="handle-object.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="36. ms Windows Specific"
  href="node922.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="A. undocumented Modules"
  href="undoc.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="handle-object.html">36.3.1 Registry Handle Objects</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="node922.html">36. MS Windows Specific</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="undoc.html">A. Undocumented Modules</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
